package com.ncloud.msg.mapper;

import com.ncloud.msg.entity.Email;
import org.apache.ibatis.annotations.*;
import java.util.List;

@Mapper
public interface EmailMapper {
	
	@Insert(value = ("insert into bs_o_email (msg_id,sys_code,subject,msg_from,msg_to,content,attach,template_name,msg_type,date_order,cc,"
			+ "bcc,msg_code,msg_result,create_time,msg_exception,para_code2,para_code1) values(#{msgId},#{sysCode},#{subject}," +
			"#{msgFrom},#{msgTo},#{content},#{attach},#{templateName},#{msgType},#{dateOrder},#{cc},#{bcc},#{msgCode},#{msgResult},now(),#{msgException},#{paraCode2},#{paraCode1});"))
	int insertEmail(Email eMail);
	
	@Update(value = ("update bs_o_email set msg_code = #{msgCode},msg_result = #{msgResult},update_time =now(),msg_exception = "
			+ "#{msgException} where msg_id = #{msgId};"))
	int updateEmail(Email email);

	@Select(value = { "select * from bs_o_email where msg_code = #{0} limit #{1} for update"  })
	@Results({ @Result(column = "msg_id", property = "msgId"), @Result(column = "sys_code", property = "sysCode"),
			@Result(column = "subject", property = "subject"),
			@Result(column = "msg_from", property = "msgFrom"),
			@Result(column = "msg_to", property = "msgTo"),
			@Result(column = "content", property = "content"),
			@Result(column = "attach", property = "attach"),
			@Result(column = "template_name", property = "templateName"),
			@Result(column = "msg_type", property = "msgType"),
			@Result(column = "date_order", property = "dateOrder"),
			@Result(column = "cc", property = "cc"),
			@Result(column = "bcc", property = "bcc"),
			@Result(column = "msg_code", property = "msgCode"), @Result(column = "msg_result", property = "msgResult"),
			@Result(column = "create_time", property = "createTime"), @Result(column = "update_time", property = "updateTime"),
			@Result(column = "msg_exception", property = "msgException"),
			@Result(column = "para_code1", property = "paraCode1"), @Result(column = "para_code2", property = "paraCode2")
	})
	public List<Email> getEmailInfos(String msgCode, int limit);

	/*导入历史数据*/
	@Insert(value = "insert into bs_oh_email(msg_id,sys_code,subject,msg_from,msg_to,content,attach,template_name,msg_type,date_order,cc,"
			+ "bcc,msg_code,msg_result,create_time,msg_exception,para_code2,para_code1)" +
			" select msg_id,sys_code,subject,msg_from,msg_to,content,attach,template_name,msg_type,date_order,cc,"
			+ "bcc,msg_code,msg_result,create_time,msg_exception,para_code2,para_code1 from bs_o_email where msg_id = #{msgId}")
	public int insertHisEmail(Long msgId);

	@Delete("delete from bs_o_email where msg_id =#{msgId}")
	public int deleteEmailById(Long msgId);

	/**/
}
